package openase.audiosearch.comm.response.decoder.factory;

import openase.audiosearch.comm.response.Response;
import openase.audiosearch.comm.response.ResponseType;
import openase.audiosearch.comm.response.decoder.ExecutionErrorResponseDecoder;
import openase.audiosearch.comm.response.decoder.RegistrationSuccessfulResponseDecoder;
import openase.audiosearch.comm.response.decoder.ResponseDecoder;
import openase.audiosearch.comm.response.decoder.SearchResultResponseDecoder;
import openase.audiosearch.comm.response.decoder.UnknownRequestResponseDecoder;

public class ResponseDecoderFactory {

	private ResponseDecoderFactory() {
	}

	@SuppressWarnings("unchecked")
	public static <T extends Response> ResponseDecoder<T> getDecoder(ResponseType type) {
		if (type == null) {
			return (ResponseDecoder<T>) new UnknownRequestResponseDecoder();
		}

		switch (type) {
		case EXECUTION_ERROR:
			return (ResponseDecoder<T>) new ExecutionErrorResponseDecoder();
		case REGISTRATION_SUCCESFUL:
			return (ResponseDecoder<T>) new RegistrationSuccessfulResponseDecoder();
		case SEARCH_RESULT:
			return (ResponseDecoder<T>) new SearchResultResponseDecoder();
		}

		return (ResponseDecoder<T>) new UnknownRequestResponseDecoder();
	}

}
